<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%@ taglib prefix="bigk" uri="/bigk-tags"%>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display" %>

<s:if test="pId == null">
    <s:set var="actionName">save</s:set>
    <s:set var="titleKey">invoicesPurchasersAction.title.create</s:set>
</s:if>
<s:else>
    <s:set var="actionName">update</s:set>
    <s:set var="titleKey">invoicesPurchasersAction.title.update</s:set>
</s:else>

<html>

  <head>
    <title><s:text name="invoicesPurchasersAction.title"/></title>
  </head>

  <body>

    <p class="wwPageTitle">
      <img src="<s:url value='/images/purchaser.gif'/>"/>
      <s:text name="%{#titleKey}">
        <s:param value="invoice.year"/>
        <s:param value="invoice.number"/>
      </s:text>
    </p>

    <s:actionerror />
    <s:actionmessage/>
    <s:fielderror />

    <s:form namespace="/invoicesPurchasers"
            action="%{#actionName}"
            method="POST"
            cssClass="wwFilterTable">

      <s:hidden name="pId" />

      <tr>
        <th colspan="2">
          <s:text name="%{#titleKey}">
            <s:param value="invoice.year"/>
            <s:param value="invoice.number"/>
          </s:text>
        </th>
      </tr>

      <s:select key="invoicePurchaser.role"
                name="model.purchaserRoleId"
                required="true"
                list="purchasersRolesList"
                listKey="id"
                listValue="groupName" />

      <tr>
        <td colspan="2">
          <SCRIPT type="text/javascript">
          function showPurchasersChooser() {
              var url = '<s:url namespace="/choosers" action="purchasers/chooserList" />';
        	  window.open(url, 'PurchasersChooser', 'width=580,height=750,top=100,left=200,resizable=yes,scrollbars=yes');
          }
          function purchasersChooserChoosed(name, address, nip) {
        	  var obj = null;
        	  obj = document.getElementById("purchaserNameId");
        	  if (obj) obj.value = name;

              var obj = null;
              obj = document.getElementById("purchaserAddressId");
              if (obj) obj.value = address;

              var obj = null;
              obj = document.getElementById("purchaserNipId");
              if (obj) obj.value = nip;
          }
          </SCRIPT>

          <s:url id="imageLink" value='/images/purchaser.gif'/>          
          <p class="infoText">
			  <img src="<s:url value='/images/info.gif'/>"/>
	          <s:text name="invoicesPurchasersAction.purchaserData.prompt">
	            <s:param value="%{'showPurchasersChooser()'}" />
	            <s:param value="%{#imageLink}" />
	          </s:text>          
          </p>
        </td>
      </tr>

      <s:textarea id="purchaserNameId"
      			  key="invoicePurchaser.name"
                  name="model.name"
                  required="true"
                  cols="75"
                  rows="2" />
               
      <s:textarea id="purchaserAddressId"
      			  key="invoicePurchaser.address"
                  name="model.address"
                  required="true"
                  cols="75"
                  rows="2" />

      <s:textfield id="purchaserNipId"
      			   key="invoicePurchaser.nip"
                   name="model.nip"
                   size="15"
                   maxlength="13" />

      <tr>
        <td colspan="2" class="wwFilterTableButtonBar">
          <s:submit key="button.submit" cssClass="inputButton" theme="simple"/>
          <s:submit key="button.cancel" cssClass="inputButton" theme="simple" action="backToInvoice" />
        </td>
      </tr>
      
    </s:form>

  </body>

</html>
